﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASKM.Rachao.Model.Domain
{
    /// <summary>
    /// Base class for domain classes
    /// </summary>
    public abstract class BaseDomain: IDisposable
    {

        #region Attributes

        /// <summary>
        /// Object context
        /// </summary>
        private RachaoEntities _ctxRachao;

        #endregion

        #region Properties

        public RachaoEntities CtxRachao
        {
            get
            {
                if (this._ctxRachao == null)
                    this._ctxRachao = new RachaoEntities();

                return this._ctxRachao;
            }
        }

        #endregion


        #region IDisposable Members

        private bool _isDisposed;

        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Dispose
        /// </summary>
        /// <param name="isDisposing"></param>
        public void Dispose(bool isDisposing)
        {
            if (!_isDisposed)
            {
                if (isDisposing)
                    if (this._ctxRachao != null)
                        this._ctxRachao.Dispose();

                _isDisposed = true;
            }
        }

        #endregion
    }
}
